package com.jhgsys.internal.incentive.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jhgsys.internal.incentive.entity.IncentiveGoodsOrderDtl;
import com.jhgsys.internal.incentive.mapper.IncentiveGoodsOrderDtlMapper;
import com.jhgsys.internal.incentive.service.IIncentiveGoodsOrderDtlService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 安全奖励订单明细 Service实现
 *
 * @author zhangwei
 * @date 2024-09-02 11:28:11
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class IncentiveGoodsOrderDtlServiceImpl extends ServiceImpl<IncentiveGoodsOrderDtlMapper, IncentiveGoodsOrderDtl> implements IIncentiveGoodsOrderDtlService {

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     * @param request QueryRequest
     * @param incentiveGoodsOrderDtl incentiveGoodsOrderDtl
     * @return IPage<IncentiveGoodsOrderDtl>
    */
    @Override
    public IPage<IncentiveGoodsOrderDtl> findIncentiveGoodsOrderDtlPage(QueryRequest request, IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
        LambdaQueryWrapper<IncentiveGoodsOrderDtl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveGoodsOrderDtl::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<IncentiveGoodsOrderDtl> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     * @param incentiveGoodsOrderDtl incentiveGoodsOrderDtl
     * @return List<IncentiveGoodsOrderDtl>
     */
    @Override
    public List<IncentiveGoodsOrderDtl> findIncentiveGoodsOrderDtlList(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
	    LambdaQueryWrapper<IncentiveGoodsOrderDtl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveGoodsOrderDtl::getDeletedFlg, 0);
		// TODO 设置查询条件
        if(StringUtils.isNotBlank(incentiveGoodsOrderDtl.getGoodsOrderId())){
            queryWrapper.eq(IncentiveGoodsOrderDtl::getGoodsOrderId,incentiveGoodsOrderDtl.getGoodsOrderId());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zhangwei
    * @date 2024-09-02 11:28:11
    * @param id
    * @return IncentiveGoodsOrderDtl
    */
    @Override
    public IncentiveGoodsOrderDtl findIncentiveGoodsOrderDtlById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     * @param incentiveGoodsOrderDtl incentiveGoodsOrderDtl
     */
    @Override
    @Transactional
    public void createIncentiveGoodsOrderDtl(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
        incentiveGoodsOrderDtl.setCreatedTime(new Date());
        this.save(incentiveGoodsOrderDtl);
    }

    /**
     * 修改
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     * @param incentiveGoodsOrderDtl incentiveGoodsOrderDtl
     */
    @Override
    @Transactional
    public void updateIncentiveGoodsOrderDtl(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl) {
        incentiveGoodsOrderDtl.setUpdatedTime(new Date());
        this.saveOrUpdate(incentiveGoodsOrderDtl);
    }

    /**
     * 逻辑删除
     * @author zhangwei
     * @date 2024-09-02 11:28:11
     * @param incentiveGoodsOrderDtl incentiveGoodsOrderDtl
     * @param incentiveGoodsOrderDtlIds incentiveGoodsOrderDtlIds
     */
    @Override
    @Transactional
    public void deleteIncentiveGoodsOrderDtl(IncentiveGoodsOrderDtl incentiveGoodsOrderDtl,String incentiveGoodsOrderDtlIds) {
        List<String> list = Arrays.asList(incentiveGoodsOrderDtlIds.split(StringPool.COMMA));
        this.baseMapper.update(incentiveGoodsOrderDtl,new LambdaQueryWrapper<IncentiveGoodsOrderDtl>().in(IncentiveGoodsOrderDtl::getGoodsOrderDtlId,list));
	}

    /**
    * 物理删除
    * @author zhangwei
    * @date 2024-09-02 11:28:11
    * @param incentiveGoodsOrderDtlIds incentiveGoodsOrderDtlIds
    */
    @Override
    @Transactional
    public void physicallyDeleteIncentiveGoodsOrderDtl(String incentiveGoodsOrderDtlIds) {
        List<String> list = Arrays.asList(incentiveGoodsOrderDtlIds.split(StringPool.COMMA));
        LambdaQueryWrapper<IncentiveGoodsOrderDtl> wapper = new LambdaQueryWrapper<>();
        wapper.in(IncentiveGoodsOrderDtl::getGoodsOrderDtlId,list);
        this.remove(wapper);
    }
}
